﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/**
* @Author: AdinZ
* @Q  Q : 1454269
* @Email:adinz@adinz.com
* @Created: 2014/4/7 22:30:13
* */
namespace Web.plug
{
    /// <summary>
    /// number 的摘要说明
    /// </summary>
    public class number : IHttpHandler
    {
        Novel.Sys.BLL.novel_article bll = new Novel.Sys.BLL.novel_article();
        public void ProcessRequest(HttpContext context)
        {
            //context.Response.ContentType = "text/plain";
            //context.Response.Write("Hello World");
            string action = context.Request["action"];
            string sid = context.Request["id"];
            if (!string.IsNullOrEmpty(sid))
            {
                int id = int.Parse(sid);
                switch (action)
                {
                    case "hits":
                        hits(context, id);
                        break;
                    case "downloads":
                        downloads(context, id);
                        break;
                    default:
                        hits(context, id);
                        break;
                }
            }
            else
            {
                Random r = new Random();
                int num = 0;
                num = r.Next(1000, 100000);
                context.Response.Write("document.write('" + num + "');");
            }
        }

        public void hits(HttpContext context, int id)
        {
            int num = bll.GetHits(id)+1;
            bll.UpdateHits(id, num);
            context.Response.Write("document.write('" + num + "');");
        }

        public void downloads(HttpContext context, int id)
        {
            int num = bll.GetDownloads(id)+1;
            bll.UpdateDownloads(id, num);
            context.Response.Write("document.write('" + num + "');");
        }


        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}